"stat" problems

Got a problem with 'stat' on empty but not 'ejected' drives

Stat stat = create ("D:\\")

stat returns non-null even when there is no DVD in the drive; OK.

When I insert a DVD and then remove the DVD without first "eject"ing it, when I run the above code I get this dialog error from the OS (not from DOORS):

"There is no disk in the drive, Please insert a disk into drive D:"
Cancel Try Again Continue

When I use windows explorer to manually 'eject' the drive on d:\, then the error goes away.

How can I suppress that error in DXL? surrounding with noError()/lastError() doesn't work. Is it possible this can be done as a Property of the D:\ drive itself? Something to do with write-cache-through gobbly-gook? Is there some mechanism in DXL that allows me to detect this condition before using "stat"?

These did not work, always generate the error dialog even when surrounded with noError/lastError.
// string D = "D:\\"
// Stream str = read("D:\\") // Still get "no disk in drive" error
//str = read(D, 0) // Still get "no disk in drive" error
// for NameFile in directory(D) do
//Stat stt = create(symbolic(D)) // always null but does NOT trigger dialog however.
//string Contents = readFile(D) // Triggers dialog

  • Louie

llandale - Thu Feb 24 12:02:55 EST 2011

Re: "stat" problems
Mathias Mamsch - Thu Feb 24 18:38:47 EST 2011

This seems to do the trick:
 

string res = "NUN"
string drive = "F:"
win32SystemWait_ ("cmd.exe /C dir " drive, res, -1)
res = ansi res
 
int d1,d2; bool diskInDrive = findPlainText(res, "F:", d1, d2, false)
print "Disc inserted: " diskInDrive "\n"
 
print "Result: " res "\n"

 


Hope this helps, regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Re: "stat" problems
llandale - Fri Feb 25 14:51:19 EST 2011

Mathias Mamsch - Thu Feb 24 18:38:47 EST 2011

This seems to do the trick:
 

string res = "NUN"
string drive = "F:"
win32SystemWait_ ("cmd.exe /C dir " drive, res, -1)
res = ansi res
 
int d1,d2; bool diskInDrive = findPlainText(res, "F:", d1, d2, false)
print "Disc inserted: " diskInDrive "\n"
 
print "Result: " res "\n"

 


Hope this helps, regards, Mathias

 

 

 


Mathias Mamsch, IT-QBase GmbH, Consultant for Requirement Engineering and D00RS

 

 

Thanks. Turned it into the below (I'm a library function kind-a-guy!). What is the 'ansi' line for?

I notice that when there is an issue with the command itself (e.g. mis-spell "cmddd.exe"), the Result shows positive.

Funny thing about this is that I've always failed trying to use win32SystemWait_, its never worked for me before even running code that other's made work. Very strange; may need to resurect that and fix my script that does that work, then has an awkward "wait for black window to close" pause "ack" after calling "system". (That code compares two text files using "fc.exe").
 

  • Louie
//***************************************
bool    fFiles_IsDriveAvailable(string in_Drive)
{     // Is the Drive avaiable for reading right now?
        // in_Drive is a drive letter, looks like "A" or "c" or "D" or "K"
 
        // Origin of this function by Mathias Mamsch posted 2011-Feb-24 here:
        //      https://www.ibm.com/developerworks/forums/thread.jspa?threadID=362528&tstart=0
 
        // This Function gracefully handles these cases:
        // o There is no drive mapped to that letter
        // o There is a drive, but no disk inserted at this time
        // o You lack 'R'ead rights to the drive
        // o Drive recently had a disk in place, but it was removed without properly 'Ejecting' it.
        //      This is the superiority of this function over attempting 'stat(Drive)' calls,
        //      which in this case causes the system to prompt you to insert a disk.
 
        if (null in_Drive)      return(false)
 
        string  Result  = "", Drive = ""
        bool    IsAvail = false
        int     d1, d2
        string  COMSPEC = "", SysCommand
 
        Drive   = in_Drive ":\\"
 
        COMSPEC = getenv("COMSPEC")           // Perhaps will fail in the future
        if (null COMSPEC) COMSPEC = "cmd.exe" // This will probably work
 
        SysCommand      = COMSPEC " /c dir " Drive
                // print "\t\t>>fFiles_IsDriveAvailable, [COMSPEC] [SysCommand] = [" COMSPEC "]\t[" SysCommand "]\n"
 
        win32SystemWait_ (SysCommand, Result, -1)
//      Result = ansi(Result)
 
        if (null Result) return(true) //?? win32SystemWait_ didn't work??
 
        IsAvail         = findPlainText(Result, Drive, d1, d2, false)
                // print "\t>>fFiles_IsDriveAvailable, " Drive "\tDisc inserted: " IsAvail "\tResult: " Result
        return(IsAvail)
}     // end fFiles_IsDriveAvailable()
 
 
//*****************************************
void    DoTest(string in_Drive)
{
        print in_Drive "\tDisc inserted: " (fFiles_IsDriveAvailable(in_Drive)) "\n"
}
                        // Expected, Situation, Rationale
DoTest("A")   //      Yes Drive, no disk
DoTest("C")   // OK   Yes Drive, yes disk
DoTest("c")   // OK           lower case OK
DoTest("D")   //      Yes Drive, disc removed without Ejecting it
DoTest("F")   //      Yes Drive, no thumb drive inserted
DoTest("K")   // OK   Yes Mapped network drive
DoTest("M")   //      No such drive
DoTest("T")   //      Yes drive, but I have no Read rights
DoTest("4")   //              Correctly gets error "The system cannot find the path specified."
DoTest("zz")  //              Correctly gets error "... volume label syntax is incorrect."
DoTest("z5")  //              Correctly gets error "... volume label syntax is incorrect."

Re: "stat" problems
tlwtheq - Wed Mar 09 12:43:28 EST 2011

OFF TOPIC.

Louie, where are you these days? Tara.Wilk@itt.com